#include <iostream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <string>

bool checkBrackets(std::string inputStr) {
    std::stack<char> bracketStack;
    std::unordered_map<char, char> bracketsMap = {{'(', ')'}, {'{', '}'}, {'[', ']'}, {'<', '>'}};
    std::unordered_set<char> openingBrackets = {'(', '{', '[', '<'};

    for (char ch : inputStr) {
        if (openingBrackets.count(ch)) {
            bracketStack.push(ch);
        } else if (!bracketStack.empty() && ch == bracketsMap[bracketStack.top()]) {
            bracketStack.pop();
        } else {
            return false;
        }
    }

    return bracketStack.empty();
}

int main() {
    std::string inputSequence;
    std::cout << "Введите скобочную последовательность: ";
    std::cin >> inputSequence;

    bool result = checkBrackets(inputSequence);

    std::cout << std::boolalpha << result << std::endl;

    return 0;
}
